package cn.tedu.finance.service.impl;

import cn.tedu.finance.mapper.InvoiceMapper;
import cn.tedu.finance.pojo.dto.InvoiceQuery;
import cn.tedu.finance.pojo.dto.InvoiceSaveParam;
import cn.tedu.finance.pojo.entity.Invoice;
import cn.tedu.finance.pojo.vo.InvoiceVO;
import cn.tedu.finance.service.InvoiceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class InvoiceServiceImpl implements InvoiceService {
    @Autowired
    InvoiceMapper invoiceMapper;


    @Override
    public List<InvoiceVO> selectInvoice(InvoiceQuery invoiceQuery) {
        log.debug("查询发票信息业务:{}", invoiceQuery);
        List<InvoiceVO> list = invoiceMapper.selectInvoice(invoiceQuery);
        return list;
    }

    @Override
    public void saveInvoice(InvoiceSaveParam invoiceSaveParam) {
        log.debug("保存发票申请业务：{}", invoiceSaveParam);
        Invoice invoice = new Invoice();
        BeanUtils.copyProperties(invoiceSaveParam, invoice);
        invoice.setCreateTime(new Date());
        invoiceMapper.saveInvoice(invoice);
    }

    @Override
    public void cancelApplication(Long id) {
        log.debug("取消发票申请业务：{}", id);
        invoiceMapper.cancelApplication(id);
    }
}
